package com.hwadee.mapper;

import com.hwadee.pojo.ElderUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ElderUserMapper {

        //条件查询老年用户列表
        @Select("<script>" +
                "SELECT * FROM elder_user WHERE 1=1 " +
                "<if test='username != null and username != \"\"'> AND username LIKE CONCAT('%', #{username}, '%') </if>" +
                "<if test='phone != null and phone != \"\"'> AND phone LIKE CONCAT('%', #{phone}, '%') </if>" +
                "</script>")
        List<ElderUser> findByCondition(@Param("username") String username, @Param("phone") String phone);

        //更新老年用户信息
        @Update("UPDATE elder_user SET username=#{username}, phone=#{phone}, status=#{status} WHERE id=#{id}")
        void update(ElderUser user);

        //根据 ID 删除老年用户
        @Delete("DELETE FROM elder_user WHERE id = #{id}")
        void deleteById(Integer id);

        //插入一条新的老年用户记录
        @Insert("INSERT INTO elder_user (id, username, phone, status, role) VALUES (#{id}, #{username}, #{phone}, #{status}, #{role})")
        void insert(ElderUser user);
}
